package 力扣_中等题;

/**
 * @author 连安利
 * @version 1.0
 * @date 2021/3/18 16:37
 */
public class 反转链表2 {
    public ListNode reverseBetween(ListNode head, int left, int right) {
        if(head == null || head.next == null || right - left < 1){
            return head;
        }
        ListNode result = new ListNode(0);
        result.next = head;
        ListNode pre = result;
        for(int i=0; i<left-1; ++i ){
            pre = pre.next;
        }
        ListNode cur = pre.next, temp;
        for(int i=1; i<=right-left; ++i ){
            temp = cur.next;
            cur.next = temp.next;
            temp.next = pre.next;
            pre.next = temp;
        }
        return result.next;
    }

    public static void main(String[] args) {
        ListNode node = new ListNode(0);
    }

}
